//
//  MainViewController.m
//  CameraDemo
//
//  Created by sanfang on 2017/2/18.
//  Copyright © 2017年 ziz. All rights reserved.
//

#import "MainViewController.h"

#import "XXCameraTool.h"
#import "XXMainView.h"
#import "ViewController.h"

@interface MainViewController ()
{
    XXMainView *mainView;
}
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.hidden = YES;
    
    mainView = [[XXMainView alloc]initWithFrame:self.view.bounds];
    self.view = mainView;

    [mainView.cameraBtn addTarget:self action:@selector(enterCameraPage:) forControlEvents:UIControlEventTouchUpInside];
    [mainView.beautifyBtn addTarget:self action:@selector(enterBeautifyPage:) forControlEvents:UIControlEventTouchUpInside];
    [mainView.torchBtn addTarget:self action:@selector(openTorch:) forControlEvents:UIControlEventTouchUpInside];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    mainView.torchBtn.selected = [[XXCameraTool shareInstance] getTorchState];
}
#pragma mark === btnclickMethod ===
-(void)enterCameraPage:(UIButton *)btn
{
   UIViewController *crl = [self.storyboard instantiateViewControllerWithIdentifier:@"camera"];
    [self.navigationController pushViewController:crl animated:YES];

}

-(void)enterBeautifyPage:(UIButton *)btn
{
    
}

-(void)openTorch:(UIButton *)btn
{
    btn.selected = !btn.selected;
    [[XXCameraTool shareInstance] setTorchOn:btn.selected];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
